package com.epam.qanda.web.servlet.admin;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.epam.qanda.db.model.Message;
import com.epam.qanda.db.service.MessageService;

public class ShowMessagesServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
    public ShowMessagesServlet() {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	
		
		List<Message> messages;
		MessageService service = new MessageService();
		
		
		
		
		String path = request.getServletPath();	
		
		if(path.equals("/ureadMessages")){
			
			messages = service.getUnreadMessages();
			
		} else if(path.equals("/alreadyReadMessages")){
			
			messages = service.getAlreadyReadMessages();
			
		} else {
			messages = new MessageService().getAllMessages();
		}
		
		
		
		
		

		request.setAttribute("messages", messages);
		request.getRequestDispatcher("WEB-INF/pages/messages.jsp").forward(request, response);
		
		
	}
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		System.out.println("show messages post");
	}

}
